package com.woniu.microassetserver.controller;


import com.github.pagehelper.PageInfo;
import com.woniu.microassetserver.service.AssetsParameterService;
import com.woniu.microcommonsserver.entity.AssetsParameterEntity;
import com.woniu.microcommonsserver.entity.ResultMsg;
import com.woniu.microcommonsserver.param.PageResult;
import com.woniu.microcommonsserver.param.ResponseMsg;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 
 *
 * @author luoyue
 * @email 1316756108@qq.com
 * @date 2021-01-26
 */
@RestController
@RequestMapping("/assets")
public class AssetsParameterController {

    @Resource
    private AssetsParameterService assetsParameterServiceImpl;


    @RequestMapping(value="/more",produces = {"application/json;charset=utf-8"})
    public ResultMsg saveAssetsParameter(@RequestBody AssetsParameterEntity assetsParameterEntity) {
        System.out.println(assetsParameterEntity);
        System.out.println("新增");
        ResultMsg resultMsg = new ResultMsg(200,"新增成功",null);
        assetsParameterServiceImpl.saveAssetsParameter(assetsParameterEntity);
        System.out.println(assetsParameterEntity);
        System.out.println("新增成功");
        return resultMsg;
    }


    @PutMapping(value="/id",produces = {"application/json;charset=utf-8"}) /*AssetsParameterBean assetsParameterBean, @PathVariable("id") Long id*/
    public ResultMsg updateAssetsParameter(@RequestBody AssetsParameterEntity assetsParameterEntity){
        ResultMsg resultMsg = new ResultMsg(200,"更新成功",null);
        System.out.println(assetsParameterEntity);


        assetsParameterServiceImpl.updateAssetsParameter(assetsParameterEntity);
        return resultMsg;
    }


    @DeleteMapping(value="/delete",produces = {"application/json;charset=utf-8"})
    public ResultMsg deleteAssetsParameter( Integer id) {

        System.out.println("添加");
        ResultMsg resultMsg = new ResultMsg(200,"删除成功",null);
        assetsParameterServiceImpl.deleteAssetsParameter(id);
        System.out.println("删除成功");
        return resultMsg;
    }


    @GetMapping(value="/page",produces = {"application/json;charset=utf-8"})
    public ResponseMsg findAssetsParameter(Integer pageNum, Integer pageSize, AssetsParameterEntity assetsParameterEntity) {



        PageInfo<AssetsParameterEntity> pageInfo =assetsParameterServiceImpl.findAllByParams(pageNum, pageSize, assetsParameterEntity);

        PageResult<AssetsParameterEntity> pageResult=new PageResult<AssetsParameterEntity>();
        pageResult.setRows(pageInfo.getList());
        pageResult.setTotal(pageInfo.getTotal());

        return ResponseMsg.builder().code(200).msg("查询陈工").data(pageResult).build();

    }


}
